/*
 * MainFrame.java
 *
 * Created on __DATE__, __TIME__
 */

package ui;

import java.awt.Component;

import javax.swing.JInternalFrame;

/**
 *
 * @author  __USER__
 */
public class MainFrame extends javax.swing.JFrame {

	/** Creates new form MainFrame */
	public MainFrame() {
		initComponents();
		thisFrame = this;
	}
	
	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	//GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		jDesktopPane1 = new javax.swing.JDesktopPane();
		jMenuBar1 = new javax.swing.JMenuBar();
		jMenu1 = new javax.swing.JMenu();
		idAddPatientMenuItem = new javax.swing.JMenuItem();
		idPatientMasterMenuItem = new javax.swing.JMenuItem();
		idPatientListMenuItem = new javax.swing.JMenuItem();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		setMinimumSize(new java.awt.Dimension(800, 600));

		jDesktopPane1.setBackground(new java.awt.Color(255, 255, 255));
		jDesktopPane1.setMaximumSize(new java.awt.Dimension(750, 550));

		jMenuBar1.setMaximumSize(new java.awt.Dimension(31, 50));

		jMenu1.setText("File");

		idAddPatientMenuItem.setText("Add Patient");
		idAddPatientMenuItem
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						idAddPatientMenuItemActionPerformed(evt);
					}
				});
		jMenu1.add(idAddPatientMenuItem);

		idPatientMasterMenuItem.setText("Patient Master");
		idPatientMasterMenuItem
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						idPatientMasterMenuItemActionPerformed(evt);
					}
				});
		jMenu1.add(idPatientMasterMenuItem);

		idPatientListMenuItem.setText("Patient List");
		idPatientListMenuItem
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						idPatientListMenuItemActionPerformed(evt);
					}
				});
		jMenu1.add(idPatientListMenuItem);

		jMenuBar1.add(jMenu1);

		setJMenuBar(jMenuBar1);

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addComponent(
				jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 709,
				Short.MAX_VALUE));
		layout.setVerticalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addComponent(
				jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 509,
				Short.MAX_VALUE));

		pack();
	}// </editor-fold>
	//GEN-END:initComponents

	private void idPatientListMenuItemActionPerformed(
			java.awt.event.ActionEvent evt) {
		JInternalFrame[] allFrames = jDesktopPane1.getAllFrames();
		boolean alreadyThere = false;
		for (JInternalFrame ji : allFrames) {
			if (ji instanceof PatientList) {
				jDesktopPane1.getDesktopManager().maximizeFrame(ji);
				alreadyThere = true;
			}
		}
		if (!alreadyThere) {
			PatientList patientList = (PatientList) jDesktopPane1
					.add(new PatientList());
			jDesktopPane1.getDesktopManager().maximizeFrame(patientList);
		}
	}

	private void idPatientMasterMenuItemActionPerformed(
			java.awt.event.ActionEvent evt) {
		JInternalFrame[] allFrames = jDesktopPane1.getAllFrames();
		boolean alreadyThere = false;
		for (JInternalFrame ji : allFrames) {
			if (ji instanceof PatientMaster) {
				jDesktopPane1.getDesktopManager().maximizeFrame(ji);
				alreadyThere = true;
			}
		}
		if (!alreadyThere) {
			PatientMaster patientMaster = (PatientMaster) jDesktopPane1
					.add(new PatientMaster());
			jDesktopPane1.getDesktopManager().maximizeFrame(patientMaster);
		}
	}

	private void idAddPatientMenuItemActionPerformed(
			java.awt.event.ActionEvent evt) {
		JInternalFrame[] allFrames = jDesktopPane1.getAllFrames();
		boolean alreadyThere = false;
		for (JInternalFrame ji : allFrames) {
			if (ji instanceof AddPatient) {
				jDesktopPane1.getDesktopManager().maximizeFrame(ji);//deiconifyFrame(ji);
				alreadyThere = true;
			}
		}
		if (!alreadyThere) {
			AddPatient addPatient = (AddPatient) jDesktopPane1
					.add(new AddPatient());
			jDesktopPane1.getDesktopManager().maximizeFrame(addPatient);
		}
	}

	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new MainFrame().setVisible(true);
			}
		});
	}

	//GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JMenuItem idAddPatientMenuItem;
	private javax.swing.JMenuItem idPatientListMenuItem;
	private javax.swing.JMenuItem idPatientMasterMenuItem;
	private javax.swing.JDesktopPane jDesktopPane1;
	private javax.swing.JMenu jMenu1;
	private javax.swing.JMenuBar jMenuBar1;
	// End of variables declaration//GEN-END:variables
	public static MainFrame thisFrame;
}